<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>首页</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta http-equiv="Access-Control-Allow-Origin" content="*">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<link rel="icon" href="/static/images/favicon.ico">
		<link rel="stylesheet" href="/static/lib/layui-v2.6.3/css/layui.css" media="all">
		<style id="layuimini-bg-color">
			div.layui-col-sm2 div img {
				height: 200px;
				width: 200px;
				transition: all 0.5s;
			}

			div.layui-col-sm2 div img:hover {
				transform: scale(1.1);
			}
		</style>
	</head>
	<body>
		<div class="layui-fluid"
			style="background-color: cyan;height: 60px;background-image: url(/static/images/loginbg.png);">
			<div class="layui-row">
				<div class="layui-col-sm6">
					<div class="grid-demo">
						<ul id="menu" class="layui-nav" style="background-color:transparent;">
							<li class="layui-nav-item" value="0"><a href="/">首页</a></li>
						</ul>
					</div>
				</div>
				<div class="layui-col-sm6">
					<div class="grid-demo">
						<ul id="not_login" class="layui-nav"
							style="background-color:transparent;float: right;display:block">
							<!-- <li class="layui-nav-item">
								<a href="">vip</a>
							</li> -->
							<li class="layui-nav-item">
								<a href="/login.html">登录</a>
							</li>
							<li class="layui-nav-item">
								<span>|</span>
							</li>
							<li class="layui-nav-item">
								<a href="">注册</a>
							</li>
						</ul>
						<ul id="login" class="layui-nav" style="background-color:transparent;float: right;display:none">
							<li class="layui-nav-item">
								<a id="vip" href="/web_profile.html?value=2"></a>
							</li>
							<li class="layui-nav-item">
								<a id="user_name" href="/web_profile.html?value=1"></a>
								<dl class="layui-nav-child">
									<dd>
										<a href="/web_profile.html?value=1"
											layuimini-content-href="page/user-setting.html" data-title="基本资料"
											data-icon="fa fa-gears">基本资料<span class="layui-badge-dot"></span></a>
									</dd>
									<dd>
										<a href="/web_profile.html?value=4"
											layuimini-content-href="page/user-password.html" data-title="修改密码"
											data-icon="fa fa-gears">修改密码</a>
									</dd>
									<dd>
										<hr>
									</dd>
									<dd>
										<a href="javascript:;" class="login_out">退出登录</a>
									</dd>
								</dl>
							</li>
						</ul>
					</div>
				</div>
			</div>
		</div>

		<div class="layui-container" style="margin: 30px auto; float: none;width: 90%;height: 100%;">
			<div class="layui-row layui-col-space15" id="course_body">
				<div class="layui-col-md8" id="course_title">
					<!-- <h1>标题标题标题标题标题标题标题标题标题标题标题标题标题标题标题标题标题</h1> -->
				</div>
				<div class="layui-col-md8" id="course_time">
					<!-- <span style="color: #c0c0c0;"><i class="layui-icon layui-icon-time"></i>2022/07/01</span> -->
				</div>
				<div class="layui-col-md8">
					<div class="layui-row layui-col-space15">
						<div class="layui-col-md4" id="course_img_index">
							<!-- <img src="/static/images/蜡笔01.jpeg" width="100%"> -->
						</div>
					</div>
				</div>
				<div class="layui-col-md8">
					<blockquote class="layui-elem-quote">课程介绍：</blockquote>
				</div>
				<div class="layui-col-md8" id="course_introduct">
					<!-- <p>课程来自百宝电商的抖音小店30天爆单训练营，价值3980元。从入门到精通系统学习，支持无货源模式和有货源模式。主要内容包括：抖店数据化选品、抖音小店入驻开通、抖店批量采集与上架、基础内功打造、自动采购上架发货、权重提升的三种方法、出单后的维持方法等。
					</p> -->
				</div>
				<div class="layui-col-md8">
					<blockquote class="layui-elem-quote">视频截图：</blockquote>
				</div>
				<div class="layui-col-md8">
					<div class="layui-row layui-col-space15" id="course_screenshort">
						<!-- <div class="layui-col-md6"><img src="/static/images/蜡笔01.jpeg" width="100%"></div> -->
					</div>
				</div>
				<div class="layui-col-md8">
					<blockquote class="layui-elem-quote">课程目录：</blockquote>
				</div>
				<div class="layui-col-md8" id="course_contents">
					<!-- <p>课程来无货驻开通、抖店批量采集与上架、基础内功打造、自动采购上架发货、权重提升的三种方法、出单后的维持方法等。</p> -->
				</div>
				<div class="layui-col-md8">
					<fieldset class="layui-elem-field layui-field-title"
						style="margin-top: 20px;border:dashed;border-width: 4px; border-color:#2ec770; width:95%; height:220">
						<legend>资源下载</legend>

						<div class="layui-row">
							<div class="layui-col-md12" id="course_price">
								<!-- 下载价格 <span style="color:green;font-weight:bold;font-size:30px">98</span> 元 -->
							</div>
							<!-- 	<div class="layui-col-md2">
							</div> -->
							<div class="layui-col-md12 layui-col-md-offset8">
								VIP免费
								<button type="button" class="layui-btn layui-btn layui-btn-warm" value="0"><a
										href="/web_profile.html?value=2">升级VIP</a></button>
								<button type="button" class="layui-btn layui-btn-primary layui-border-green" value="0"
									id="paybutton">立即购买</button>
							</div>
						</div>
						<div class="layui-col-md10 layui-col-md-offset4">如有发现链接失效，请联系站长</div>

					</fieldset>
				</div>
			</div>
		</div>


		<script src="/static/lib/layui-v2.6.3/layui.js"></script>

		<script>
			function getCookie(name) {
				var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
				return r ? r[1] : undefined;
			}

			function getlocalURL() {
				var localURL = window.location.href;
				var url = localURL.split("&")
				return url[0]
			}

			function getQueryString(name) {
				var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
				var r = window.location.search.substr(1).match(reg);
				if (r != null) {
					return decodeURI(r[2]);
				}
				return '';
			}

			var cous = getQueryString("couser_id")


			layui.use(['form', 'layedit', 'laydate', 'flow', 'element', 'layer'], function() {
				var form = layui.form,
					layer = layui.layer,
					layedit = layui.layedit,
					laydate = layui.laydate,
					flow = layui.flow,
					element = layui.element,
					$ = layui.jquery;


				var avatar_img = "";
				var is_vip = "";
				//检查登录状态
				$.ajax({
					type: "post", //get或者post
					headers: {
						'X-CSRFToken': getCookie('csrf_token')
					},
					url: '/api/v1.0/check_login',
					data: {}, //参数 接口传参 json对象
					success: function(res) {
						// console.log(res);
						if ("0" == res.code) {
							if (res.data.user_id == "1") {
								location.href = "/"
							} else {
								// location.href = "/web_index.html"
								avatar_img = res["data"]["avatar"]
								is_vip = res["data"]["is_vip"]
								console.log(res["data"]["avatar"]);
								console.log(res["data"]["is_vip"]);
								var not_login = document.getElementById('not_login');
								not_login.style.display = 'none'
								var login = document.getElementById('login');
								login.style.display = 'block'
								var a = document.getElementById('user_name'); //获取a元素对象
								if (avatar_img == "") {
									a.innerHTML = '<img src="' + '//t.cn/RCzsdCq' +
										'" class="layui-nav-img">' +
										res.data.user_name;
								} else {
									a.innerHTML = '<img src="' + avatar_img +
										'" class="layui-nav-img">' +
										res.data.user_name;
								}
								var avip = document.getElementById('vip'); //获取a元素对象
								if (is_vip == 1) {
									avip.innerHTML = '<img src="/static/images/vipicon-5.png"/>';

								} else {
									avip.innerHTML = 'vip';
								}
							}

						} else {
							$(".not_login").show();
						}
					}
				});



				function addli_dl(key, value) {
					var li = document.createElement("li")
					li.className = "layui-nav-item"
					li.value = key
					li.innerHTML = '<a href="/web_courselist.html?contents=' + key + '">' + value + '</a>'
					document.getElementById("menu").appendChild(li)
					return li
				}


				//获取所有menu菜单
				$.ajax({
					type: "post", //get或者post
					contentType: 'application/json',
					headers: {
						'X-CSRFToken': getCookie('csrf_token')
					},
					url: '/api/v1.0/get_contents_all_list',
					data: {}, //参数 接口传参 json对象
					success: function(res) {
						$("#menu").find('span.layui-nav-bar').remove();
						var li;
						var dl = document.createElement("dl");
						dl.className = "layui-nav-child";

						$.each(res.data, function(index, value) {
							if (value.contents_level == "0") {
								li = addli_dl(value.contents_id, value.contents_name)
							}
							if (value.contents_level != "0") {

								$.each(res.data, function(index, valueparent) {
									// console.log(valueparent.contents_level)
									if (value.contents_level == valueparent.contents_id) {
										var dd = document.createElement("dd")
										dd.value = valueparent.contents_id
										dd.innerHTML =
											'<a href="/web_courselist.html?contents=' + value
											.contents_id + '">' + value.contents_name +
											'</a>'
										dl.appendChild(dd)
									}
									li.appendChild(dl)
								})
							}
						});
						element.render('ul');
						element.render('dl');
					}
				});



				var course_data = {
					"course_id": cous
				}

				// var title = ""
				// var normal_price = ""

				var order_data = {
					"course_id": cous,
					"title": "",
					"normal_price": ""
				}
				$.ajax({
					type: "post", //get或者post
					contentType: 'application/json',
					headers: {
						'X-CSRFToken': getCookie('csrf_token')
					},
					url: '/api/v1.0/get_course_detail',
					data: JSON.stringify(course_data), //参数 接口传参 json对象
					success: function(res) {
						var courseinfo = res["data"]["courseinfo"]
						order_data["title"] = courseinfo["title"]
						order_data["normal_price"] = courseinfo[
							"normal_price"]
						var image_list = res["data"]["image_list"]

						var title_div = document.getElementById("course_title")
						title_div.innerHTML = '<h1>' + courseinfo["title"] + '</h1>'

						var time_div = document.getElementById("course_time")
						time_div.innerHTML =
							'<span style="color: #c0c0c0;"><i class="layui-icon layui-icon-time"></i>' +
							courseinfo["create_time"] + '</span>'

						var img_div = document.getElementById("course_img_index")
						img_div.innerHTML = '<img src="' + courseinfo["index_image_url"] + '" width="100%">'

						var introduct_div = document.getElementById("course_introduct")
						introduct_div.innerHTML = '<p>' + courseinfo["introduce"] + '</p>'

						var contents_div = document.getElementById("course_contents")
						contents_div.innerHTML = '<p>' + courseinfo["contents"] + '</p>'

						var price_div = document.getElementById("course_price")
						price_div.innerHTML =
							'下载价格 <span style="color:green;font-weight:bold;font-size:30px">' + courseinfo[
								"normal_price"] + '</span> 元'


						var screenshort_div = document.getElementById("course_screenshort")
						// var screenshort_div = document.getElementById("course_screenshort")
						$.each(image_list, function(index, value) {
							console.log(value)
							screenshort_div.innerHTML += '<div class="layui-col-md3"><img src="' +
								value["screenshot_url"] + '" width="100%"></div>'
							// screenshort_div.innerHTML += '<div class="layui-col-md3"><img src="' +
							// 	value["screenshot_url"] + '></div>'
						})

					}
				});


				$('#paybutton').on("click", function() {
					$.ajax({
						type: "post", //get或者post
						headers: {
							'X-CSRFToken': getCookie('csrf_token')
						},
						contentType: "application/json",
						url: '/api/v1.0/orderalipayback',
						data: JSON.stringify(order_data), //参数接口传参 json对象
						success: function(res) {
							if (res.code == "0") {
								if (is_vip == 2) {
									var gateway_url = res.data.gateway_url
									layer.msg('正在生成订单，等待支付', function() {
										// window.open(gateway_url)
										location.href = gateway_url
									})
								} else {
									layer.msg('已经生成订单，资源正在发送您的邮箱，如果邮箱未收到，请前往购买记录页面可再次获取资源')
								}
							} else {
								layer.msg('订单生成失败，请登录后再试')
							}
						}
					});
				});




				$('.login_out').on("click", function() {
					$.ajax({
						type: "post", //get或者post
						headers: {
							'X-CSRFToken': getCookie('csrf_token')
						},
						url: '/api/v1.0/logout',
						data: {}, //参数 接口传参 json对象
						success: function(res) {
							if (res.code == "0") {
								layer.msg('退出登录成功', function() {
									// window.location = '/login.html';
									// location.href = "/login.html"
									location.href = "/web_index.html"
									// window.location.reload()
								});
							} else {
								layer.msg('退出失败')
							}
						}
					});
				});

			})
		</script>

	</body>
</html>
